package com.wangpeng.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wangpeng.commons.base.BaseController;
import com.wangpeng.model.NColumn;
import com.wangpeng.model.Organization;
import com.wangpeng.service.INColumnService;
import com.wangpeng.service.IOrganizationService;

/**
 * @description：栏目管理
 * @author：wangpeng
 * @date：2015/10/1 14:51
 */
@Controller
@RequestMapping("/column")
public class ColumnController extends BaseController {

    @Autowired
    private INColumnService columnService;

    /**
     * 部门管理主页
     *
     * @return
     */
    @GetMapping(value = "/manager")
    public String manager() {
        return "admin/column/column";
    }

    /**
     * 栏目资源树
     *
     * @return
     */
    @PostMapping(value = "/tree")
    @ResponseBody
    public Object tree() {
        return columnService.selectTree();
    }

    /**
     * 栏目列表
     *
     * @return
     */
    @RequestMapping("/treeGrid")
    @ResponseBody
    public Object treeGrid() {
        return columnService.selectTreeGrid();
    }

    /**
     * 添加栏目页
     *
     * @return
     */
    @RequestMapping("/addPage")
    public String addPage() {
        return "admin/column/columnAdd";
    }

    /**
     * 添加栏目
     *
     * @param column
     * @return
     */
    @RequestMapping("/add")
    @ResponseBody
    public Object add(NColumn column) {
    	columnService.insert(column);
        return renderSuccess("添加成功！");
    }

    /**
     * 编辑栏目页
     *
     * @param request
     * @param id
     * @return
     */
    @GetMapping("/editPage")
    public String editPage(HttpServletRequest request, Long id) {
        NColumn column = columnService.selectById(id);
        request.setAttribute("column", column);
        return "admin/column/columnEdit";
    }

    /**
     * 编辑栏目
     *
     * @param column
     * @return
     */
    @RequestMapping("/edit")
    @ResponseBody
    public Object edit(NColumn column) {
    	columnService.updateSelectiveById(column);
        return renderSuccess("编辑成功！");
    }

    /**
     * 删除栏目
     *
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
    	columnService.deleteById(id);
        return renderSuccess("删除成功！");
    }
}